package zhuyun.code.launcheractivity.model.data.interfaces

/**
 * @author: Administrator
 * @date: 2021/12/4
 */
abstract class AbstractExpandableItem<T>:IExpandable<T> {
    private var mExpandable:Boolean = false
    private val mSubItems by lazy { mutableListOf<T>() }
    override fun isExpanded():Boolean{
        return mExpandable
    }

    override fun setExpanded(expanded: Boolean) {
        mExpandable = expanded
    }

    override fun getSubItems(): List<T> {
        return mSubItems
    }

    fun hasSubItem():Boolean{
        return mSubItems.isNotEmpty()
    }

    fun addSubItem(subItem:T){
        mSubItems.add(subItem)
    }

    fun addSubItem(position:Int, subItem: T){
        if(position >= 0&&position < mSubItems.size){
            mSubItems.add(position,subItem)
        }
    }

    fun removeSubItem(subItem: T):Boolean{
        return mSubItems.remove(subItem)
    }

    fun removeSubItem(position: Int){
        if(position >= 0&&position < mSubItems.size){
            mSubItems.removeAt(position)
        }
    }

    fun contains(subItem: T):Boolean{
        return mSubItems.contains(subItem)
    }

}